<?php if (!defined('BASEPATH'))exit('No direct script access allowed');

class Mfunds extends MY_Controller {

    function __construct() {
        parent::__construct();
        
        $this->load->model('fund_model');
    }
    function index() {
        //推荐项目
        $where = array();
        $where['is_recommand'] = 1;
        $where['is_show'] = 1;
        $recommand_list = $this->fund_model->get_list($where,0,3);
        foreach ($recommand_list as $key=>$val){
            $recommand_list[$key]['url'] = site_url("mfunds/".$val['id']);
        }
        //全部项目
        $where = array();
        $where['is_recommand'] = 0;
        $where['is_show'] = 1;
        $unrecommand_list = $this->fund_model->get_list($where,0,20);
        foreach ($unrecommand_list as $key=>$val){
            $unrecommand_list[$key]['url'] = site_url("mfunds/".$val['id']);
        }
        $this->assign("recommands", $recommand_list);
        $this->assign("unrecommands", $unrecommand_list);
        $this->display("mfunds/index.html");
    }
    function detail($id =0){
        $id = $id ? intval($id) : 0;
        if(!$id){
            redirect("mfunds");
        }
        $where = array();
        $where['id'] = $id;
        $where['is_show'] = 1;
        $item = $this->fund_model->get($where);
        if(!$item){
            redirect("mfunds");
        }
        $item['description'] = strstr($item['description'],"http://") ? $item['description'] : str_replace('<img src="', '<img src="'.$this->img_url, $item['description']);
        //详情页推荐项目
        $where = array();
        $where['is_recommand'] = 0;
        $where['is_show'] = 1;
        $where['id != '] = $id;
        $recommand_list = $this->fund_model->get_list($where,0,2);
        foreach ($recommand_list as $key=>$val){
            $recommand_list[$key]['url'] = site_url("mfunds/".$val['id']);
        }
        $this->assign("recommands", $recommand_list);
        $this->assign("item", $item);
        $this->display("mfunds/detail.html");
    }
}
